Skip to content

fix(browser): Ensure suppressTracing does not leak when async #16545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2025

Conversation

mydea
Copy link
Member

@mydea mydea commented Jun 11, 2025

This changes the behavior of suppressTracing to be less problematic (or, problematic in a different way).

Today, because in the browser we do not have async context isolation, there is only a single shared top scope. Because of this, if you have code like this:

const spanPromise = suppressTracing(async () => {
  await new Promise(resolve => setTimeout(resolve, 100));
  return startInactiveSpan({ name: 'span' });
});

const span = startInactiveSpan({ name: 'span2' });

The span2 will also be suppressed, because suppressTracing forks the scope and sets data on it to ensure spans are not recorded. This is problematic as that will result in completely unrelated spans, e.g. pageload/navigation spans, being suppressed while e.g. an ongoing fetch call that is suppressed happens.

This PR changes this to instead only suppress tracing synchronously in the browser. This obviously is also not really ideal and can lead to things not being suppressed, but it feels like the better tradeoff for now.

@mydea mydea self-assigned this Jun 11, 2025
Copy link
Contributor

github-actions bot commented Jun 11, 2025

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 23.99 kB - -
@sentry/browser - with treeshaking flags 23.76 kB - -
@sentry/browser (incl. Tracing) 38.36 kB - -
@sentry/browser (incl. Tracing, Replay) 76.47 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 69.57 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 81.23 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 93.31 kB - -
@sentry/browser (incl. Feedback) 40.73 kB - -
@sentry/browser (incl. sendFeedback) 28.7 kB - -
@sentry/browser (incl. FeedbackAsync) 33.59 kB - -
@sentry/react 25.76 kB - -
@sentry/react (incl. Tracing) 40.35 kB - -
@sentry/vue 28.36 kB - -
@sentry/vue (incl. Tracing) 40.21 kB - -
@sentry/svelte 24.01 kB - -
CDN Bundle 25.48 kB - -
CDN Bundle (incl. Tracing) 38.55 kB +0.03% +11 B 🔺
CDN Bundle (incl. Tracing, Replay) 74.42 kB +0.02% +10 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 79.87 kB +0.02% +9 B 🔺
CDN Bundle - uncompressed 74.48 kB +0.11% +75 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 114.16 kB +0.06% +59 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 228.13 kB +0.03% +59 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 240.95 kB +0.03% +59 B 🔺
@sentry/nextjs (client) 42.01 kB - -
@sentry/sveltekit (client) 38.84 kB - -
@sentry/node 150.44 kB +0.01% +14 B 🔺
@sentry/node - without tracing 98.35 kB +0.02% +14 B 🔺
@sentry/aws-serverless 124.11 kB +0.01% +12 B 🔺

View base workflow run

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me, thanks for catching and fixing!

@mydea mydea force-pushed the fn/fix-suppressTracing-browser branch from 0d84387 to 8a9a722 Compare June 11, 2025 09:11
@mydea mydea force-pushed the fn/fix-suppressTracing-browser branch from 8a9a722 to 17fa89d Compare June 11, 2025 09:25
@mydea mydea merged commit fee86b0 into develop Jun 11, 2025
163 checks passed
@mydea mydea deleted the fn/fix-suppressTracing-browser branch June 11, 2025 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants